package com.liangzhong.proxy.guide
{
	import com.adobe.serialization.json.JSON;
	import com.liangzhong.constants.HttpRequestConst;
	import com.liangzhong.model.AppData;
	import com.liangzhong.model.guide.vo.GuideClubVo;
	import com.liangzhong.model.guide.vo.GuideGiftSelectVo;
	import com.liangzhong.model.guide.vo.GuidePlayerSelectVo;
	import com.liangzhong.model.guide.vo.GuideSelfSelectVo;
	import com.liangzhong.proxy.BaseProxy;
	import com.liangzhong.proxy.ProxyUtils;
	
	import flash.net.URLVariables;

	/**
	 *引导proxy 
	 * @author lake
	 * 
	 */	
	public class GuideOneProxy extends BaseProxy
	{
		public static const ProxyName :String = "GuideOneProxy";
		/**
		 * 获取俱乐部设置返回
		 */		
		public static const GET_CLUBSETTING_RESULT :String = "server/GuideOneProxy/GET_CLUBSETTING_RESULT";
		/**
		 *获取核心球员信息返回 
		 */		
		public static const GET_PLAYERSETTING_RESULT :String = "server/GuideOneProxy/GET_PLAYERSETTING_RESULT";
		/**
		 *获取自己属性返回 
		 */		
		public static const GET_SELF_PLAYER_RESULT	   :String = "server/GuideOneProxy/GET_SELF_PLAYER_RESULT";
		/**
		 *获取礼包返回 
		 */		
		public static const GET_GIFT_PACKAGE_RESULT 	:String = "server/GuideOneProxy/GET_GIFT_PACKAGE_RESULT";
		/**
		 *开始游戏返回 
		 */		
		public static const START_GAME_RESULT			:String = "server/GuideOneProxy/START_GAME_RESULT";
		
		public function GuideOneProxy(proxyName:String=ProxyName, data:Object=null)
		{
			super(proxyName, data);
		}
		/**
		 *获取俱乐部设置信息
		 */	
		public function getClubSetting():void
		{
			var variables:URLVariables = ProxyUtils.instance.getUrlVariables();
			variables.method = HttpRequestConst.GUIDE_CLUB_SETTING;
			ProxyUtils.instance.webClient(getClubSettingRes,variables,false);
		}
		/**
		 * 获取俱乐部设置信息 result
		 * @param data
		 */
		private function getClubSettingRes(data :Object):void
		{
			var str:String = String(data);
			var resultObj :Object;
			try
			{
				resultObj = JSON.decode(str)[0];
			}
			catch(e :Error)
			{
				trace("getClubSettingRes:",e);
				trace("data:",str);
				return;
			}
			if(resultObj.retcode != 0)
			{
				return;
			}
			var guideClubVo :GuideClubVo = AppData.getInstance().guideManager.guideClubVo;
			guideClubVo.parse(resultObj);
			this.sendNotification(GET_CLUBSETTING_RESULT,guideClubVo);
		}
		/**
		 *设置俱乐部信息 
		 * 
		 */		
		public function setClubSetting():void
		{
			var variables:URLVariables = ProxyUtils.instance.getUrlVariables();
			variables.method = HttpRequestConst.GUIDE_SET_CLUBINFO;
			ProxyUtils.instance.webClient(setClubSettingRes,variables,false);
		}
		/**
		 * 获取俱乐部设置信息 result
		 * @param data
		 */
		private function setClubSettingRes(data :Object):void
		{
			var str:String = String(data);
			var resultObj :Object;
			try
			{
				resultObj = JSON.decode(str)[0];
			}
			catch(e :Error)
			{
				trace("setClubSettingRes:",e);
				trace("data:",str);
				return;
			}
			if(resultObj.retcode != 0)
			{
				return;
			}
		}
		/**
		 *获取核心球员信息
		 */	
		public function getPlayerSetting():void
		{
			var variables:URLVariables = ProxyUtils.instance.getUrlVariables();
			variables.method = HttpRequestConst.GUIDE_GET_PLAYER_SETTING;
			ProxyUtils.instance.webClient(getPlayerSettingRes,variables,false);
		}
		/**
		 * 获取核心球员信息 result
		 * @param data
		 */
		private function getPlayerSettingRes(data :Object):void
		{
			var str:String = String(data);
			var resultObj :Object;
			try
			{
				resultObj = JSON.decode(str)[0];
			}
			catch(e :Error)
			{
				trace("getPlayerSettingRes:",e);
				trace("data:",str);
				return;
			}
			if(resultObj.retcode != 0)
			{
				return;
			}
			var guidePlayerSelectVo :GuidePlayerSelectVo = AppData.getInstance().guideManager.guidePlayerSelectVo;
			guidePlayerSelectVo.parse(resultObj);
			this.sendNotification(GET_PLAYERSETTING_RESULT,guidePlayerSelectVo);
		}
		/**
		 *获取本身球员数据
		 */	
		public function getSelfPlayer():void
		{
			var variables:URLVariables = ProxyUtils.instance.getUrlVariables();
			variables.method = HttpRequestConst.GUIDE_GET_SELF_PLAYER;
			ProxyUtils.instance.webClient(getSelfPlayerRes,variables,false);
		}
		/**
		 * 获取核心球员信息 result
		 * @param data
		 */
		private function getSelfPlayerRes(data :Object):void
		{
			var str:String = String(data);
			var resultObj :Object;
			try
			{
				resultObj = JSON.decode(str)[0];
			}
			catch(e :Error)
			{
				trace("getSelfPlayerRes:",e);
				trace("data:",str);
				return;
			}
			if(resultObj.retcode != 0)
			{
				return;
			}
			var guideSelfSelectVo :GuideSelfSelectVo = AppData.getInstance().guideManager.guideSelfSelectVo;
			guideSelfSelectVo.analysisData(resultObj);
			this.sendNotification(GET_SELF_PLAYER_RESULT,guideSelfSelectVo);
		}
		/**
		 *获取礼包
		 */	
		public function getGiftPakg():void
		{
			var variables:URLVariables = ProxyUtils.instance.getUrlVariables();
			variables.method = HttpRequestConst.GUIDE_GET_GIFT_PACKAGE;
			ProxyUtils.instance.webClient(getGiftPakgRes,variables,false);
		}
		/**
		 * 获取礼包 result
		 * @param data
		 */
		private function getGiftPakgRes(data :Object):void
		{
			var str:String = String(data);
			var resultObj :Object;
			try
			{
				resultObj = JSON.decode(str)[0];
			}
			catch(e :Error)
			{
				trace("getGiftPakgRes:",e);
				trace("data:",str);
				return;
			}
			if(resultObj.retcode != 0)
			{
				return;
			}
			var guideGiftSelectVo :GuideGiftSelectVo = AppData.getInstance().guideManager.guideGiftSelectVo;
			guideGiftSelectVo.parse(resultObj);
			this.sendNotification(GET_GIFT_PACKAGE_RESULT,guideGiftSelectVo);
		}
		/**
		 *开始游戏
		 */	
		public function startGame():void
		{
			var variables:URLVariables = ProxyUtils.instance.getUrlVariables();
			variables.method = HttpRequestConst.GUIDE_START_GAME;
			ProxyUtils.instance.webClient(startGameRes,variables,false);
		}
		/**
		 * 开始游戏 result
		 * @param data
		 */
		private function startGameRes(data :Object):void
		{
			var str:String = String(data);
			var resultObj :Object;
			try
			{
				resultObj = JSON.decode(str)[0];
			}
			catch(e :Error)
			{
				trace("startGameRes:",e);
				trace("data:",str);
				return;
			}
			if(resultObj.retcode != 0)
			{
				//return;
			}
			this.sendNotification(START_GAME_RESULT,resultObj);
		}
	}
}